package com.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* 异常处理器类*/
public class SysExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                                         Object o, Exception e) {
        Sysexception sysexception = null ;
        if(e instanceof Sysexception){
            sysexception=(Sysexception)e;
        }else{
            sysexception=new Sysexception("系统正在维护。。。");
        }
        //创建ModelAndView对象
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorMsg",sysexception.getMessage());
        //跳转到提示页面
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
